﻿using SCG.General;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TTEngine
{
    //TODO allow range of factions for difficulty level, not straight equality
    public static class FactionFactory
    {
        //static constrcutor
        static FactionFactory()
        {
            TypeLoader loader = new TypeLoader("Faction", "");
            foreach (Type t in loader.Types)
            {
                Faction faction = (Faction)loader.CreateInstance(t);
                _factions.Add(faction);
            }
        }

        //get a faction that can use the specified room
        public static Faction GetFactionForRoom(Room room, int difficultyLevel)
        {
            RandomList<Faction> candidates = new RandomList<Faction>();
            foreach (Faction faction in _factions)
                if (faction.DifficultyLevel == difficultyLevel)
                    if (faction.CanUseRoom(room))
                        candidates.Add(faction);
            if (candidates.Count > 0)
                return candidates.RandomValue;
            else
                return null;
        }

        //private members
        private static List<Faction> _factions = new List<Faction>();
    }
}
